package mshop.com.schild_kotlin.mvp.presenter

import android.content.Context
import mshop.com.schild_kotlin.base.applySchedulers
import mshop.com.schild_kotlin.entitys.HotBean
import mshop.com.schild_kotlin.mvp.base.BaseContract
import mshop.com.schild_kotlin.mvp.model.CategoryModel
import mshop.com.schild_kotlin.network.MyObserver

/**
 * Created by mayi on 2018/5/30.
 * @Autor CaiWF
 * @Email 401885064@qq.com
 * @TODO
 */
class CategoryPresener(var mContext: Context?, var view: BaseContract.View<HotBean>) : BaseContract.Presenter {
    val mModel: CategoryModel by lazy {
        CategoryModel()
    }

    override fun requestData() {
    }

    override fun start() {
    }

    fun getFirstCategory(categoryName: String) {
        mContext?.let {
            var observable = mModel.loadData(it, categoryName)
            observable.applySchedulers().subscribe(object : MyObserver<HotBean>(it) {
                override fun onNext(t: HotBean?) {
                    if (t != null) {
                        view.setData(t)
                    }
                }
            })
        }
    }

    fun getMoreCategory(start: Int, num: Int, categoryName: String) {
        mContext?.let {
            var observable = mModel.loadMoreData(it, start, num, categoryName)
            observable.applySchedulers().subscribe(object : MyObserver<HotBean>(it) {
                override fun onNext(t: HotBean?) {
                    if (t != null) {
                        view.setData(t)
                    }
                }
            })
        }
    }

}